package com.example.knowledge.fragement;

import android.content.Context;
import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.baselib.base.BaseMVPFragment;
import com.example.baselib.baseurl.GuidUrl;
import com.example.baselib.mvp.IPresenter;
import com.example.news.R;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

/**
 * 咨询
 */
@Route(path = GuidUrl.Consult_Fragment)
public class ConsultFragment extends BaseMVPFragment {
    private Context mContext;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "热门资讯", "养生", "慢病"
            , "睡眠", "风湿", "高血压", "糖尿病"
            , "冠心病"
    };
    private MyPagerAdapter mAdapter;

    @Override
    protected IPresenter createPresenter() {
        return null;
    }

    @Override
    protected int getLayoutResId() {
        mContext = getContext();
        return R.layout.fragment_consult;
    }

    @Override
    protected void initView(View rootView) {
        for (String title : mTitles) {
            mFragments.add(KonwConsultChildFragment.getInstance(title));
        }

        View decorView = getActivity().getWindow().getDecorView();
        ViewPager vp = rootView.findViewById(R.id.vp);
        mAdapter = new MyPagerAdapter(getActivity().getSupportFragmentManager());
        vp.setAdapter(mAdapter);

        SlidingTabLayout tabLayout_9 = rootView.findViewById(R.id.tl_9);
        tabLayout_9.setViewPager(vp);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
